package T41_T50;

import datastructure.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class T46 {
    List<TreeNode> list=new ArrayList<>();
    public void flatten(TreeNode root) {
        if(root == null||( root.left == null && root.right==null))return;
        preOrder(root);
        for (int i=0;i< list.size();i++){
            root.left=null;
            root.right=list.get(i);
            root=root.right;
        }
    }
    private void preOrder(TreeNode node){
        if (node==null)return;
        list.add(node);
        preOrder(node.left);
        preOrder(node.right);
    }
}
